import {CONFIG} from "../mutation-types";
import {initLog, initStr} from "../../util/StringUtil";

const Store = require('electron-store');

const state = {
  appId: '',
  password: '',
  level: 2,
  logMsg: '',
}

const mutations = {
  [CONFIG.SAVE_CONFIG](state, {appId, password, level}) {
    appId = initStr(appId)
    password = initStr(password)
    //内存更新
    state.appId = appId
    state.password = password
    state.level = level

    console.log(appId + "  " + password + "  " + level)

    const store = new Store();

    // 需要存储信息
    store.set('appId', appId)
    store.set('password', password)
  },
  [CONFIG.LOADED_CONFIG](state) {
    const store = new Store();
    state.appId = store.get('appId');
    state.password = store.get('password');
    //清除日志
    state.logMsg =''
  },
  [CONFIG.UPDATE_LOG_MSG](state, mLog) {
    state.logMsg += initLog(mLog)
  },
}

const getters = {}

const actions = {
  [CONFIG.LOADED_CONFIG]({commit}) {
    // do something async
    commit(CONFIG.LOADED_CONFIG)
  }
}

export default {
  state,
  mutations,
  actions
}
